#ifndef TCPNETWORK_H
#define TCPNETWORK_H

#include <QObject>
#include <QTcpSocket>
#include <QUdpSocket>
#include "NetWorkInterface.h"

//这个类不会跟封装好加密的东西，加密由上层做，这个只是用来传输数据。
class TcpNetwork : public NetworkInterface
{
    Q_OBJECT
public:
    TcpNetwork();
    void connect(const QString &hostAddress, const quint64 &hostPort) override;
    void sendData(const QByteArray &data) override;
    QByteArray readData(qint64 readBytes) override;
    void disconnect() override;
    QAbstractSocket::SocketState socketStatus() override;
protected slots:
    void onReadyRead() override;
    void onConnected() override;
    void onError(QAbstractSocket::SocketError socketError) override;
    void onDisconnected() override;

signals:
    void dataArrival(qint64 readBytes);

private:
    QTcpSocket tcpSocket;
    //接收数据的缓冲区
    QByteArray receiveBuffers[2]; // 两个接收缓冲区，一个用来接收，一个用来向上层传递数据
    QByteArray sendBuffers[2]; // 两个发送缓冲区
    // QByteArray transBuffer;
    // //当前使用的缓冲区索引
    int currentReceiveBufferIndex;
    // int currentSendBufferIndex;

    //一次性接收的最大的数据大小是
    int expectedPacketSize = 2048;
};
#endif
